package com.ruoyi.project.device.space.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.project.device.space.domain.BasCargoSpace;
import com.ruoyi.project.device.space.service.IBasCargoSpaceService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 货位管理Controller
 * 
 * @author wld
 * @date 2023-04-04
 */
@Controller
@RequestMapping("/device/space")
public class BasCargoSpaceController extends BaseController
{
    private String prefix = "device/space";

    @Autowired
    private IBasCargoSpaceService basCargoSpaceService;

    @GetMapping()
    public String space()
    {
        return prefix + "/space";
    }

    /**
     * 查询货位管理列表
     */
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(BasCargoSpace basCargoSpace)
    {
        startPage();
        List<BasCargoSpace> list = basCargoSpaceService.selectBasCargoSpaceList(basCargoSpace);
        return getDataTable(list);
    }

    /**
     * 导出货位管理列表
     */
    @Log(title = "货位管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(BasCargoSpace basCargoSpace)
    {
        List<BasCargoSpace> list = basCargoSpaceService.selectBasCargoSpaceList(basCargoSpace);
        ExcelUtil<BasCargoSpace> util = new ExcelUtil<BasCargoSpace>(BasCargoSpace.class);
        return util.exportExcel(list, "货位管理数据");
    }

    /**
     * 新增货位管理
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存货位管理
     */
    @Log(title = "货位管理", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(BasCargoSpace basCargoSpace)
    {
        return toAjax(basCargoSpaceService.insertBasCargoSpace(basCargoSpace));
    }

    /**
     * 修改货位管理
     */
    @GetMapping("/edit/{cargoSpaceId}")
    public String edit(@PathVariable("cargoSpaceId") String cargoSpaceId, ModelMap mmap)
    {
        BasCargoSpace basCargoSpace = basCargoSpaceService.selectBasCargoSpaceByCargoSpaceId(cargoSpaceId);
        mmap.put("basCargoSpace", basCargoSpace);
        return prefix + "/edit";
    }

    /**
     * 修改保存货位管理
     */
    @Log(title = "货位管理", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(BasCargoSpace basCargoSpace)
    {
        return toAjax(basCargoSpaceService.updateBasCargoSpace(basCargoSpace));
    }

    /**
     * 删除货位管理
     */
    @Log(title = "货位管理", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(basCargoSpaceService.deleteBasCargoSpaceByCargoSpaceIds(ids));
    }
    /**
     * 设备库房是否锁定修改
     */
    @Log(title = "设备库房管理", businessType = BusinessType.UPDATE)
    @PostMapping("/changeLocked")
    @ResponseBody
    public AjaxResult changeLocked(BasCargoSpace basCargoSpace)
    {
        return toAjax(basCargoSpaceService.changeLocked(basCargoSpace));
    }

}
